package com.ericom.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
@Entity
public class Province extends BaseObject {
	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof Province))
			return false;
		Province castOther = (Province) other;
		return new EqualsBuilder().append(code, castOther.code)
				.append(name, castOther.name).isEquals();
	}
	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(code).append(name).toHashCode();
	}
	@Override
	public String toString() {
		return new ToStringBuilder(this).append("id", id).append("code", code)
				.append("name", name).append("country", country)
				.append("provinces", cities).toString();
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	private Long id;
	private String code;    
    private String name;
    private Country country;
    private Set<City> cities=new HashSet<City>();
    
    public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@ManyToOne(cascade={CascadeType.REFRESH})
	@JoinColumn(name="countryId")
	public Country getCountry() {
		return country;
	}
	public void setCountry(Country country) {
		this.country = country;
	}
	@OneToMany(mappedBy="province",cascade=CascadeType.ALL,fetch=FetchType.LAZY,targetEntity=City.class)	
	public Set<City> getCities() {
		return cities;
	}
	public void setCities(Set<City> cities) {
		this.cities = cities;
	}
	public void setId(Long id) {
		this.id = id;
	}
	@Id
    @GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return id;
	}

}
